<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<c:set var="ctx" value="${pageContext.request.contextPath}"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>修改厂商</title>
	<jsp:include page="../../import.jsp" flush="true"/>
	<script type="text/javascript" src="<%=path %>/resource/lib/plugins/ajaxfileupload.js"></script>
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="基本信息" lselected="true">
			<form id="formSet1">
				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">基本信息</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">厂商名称</div>
						<div class="field">
							<input name="mfrNm" id="mfrNm" type="text" class="ui-textbox" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">社会统一信用代码</div>
						<div class="field">
							<input name="succ" id="succ" type="text" class="ui-textbox" validate="{required:true}">
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">厂商地址</div>
						<div class="field">
							<input name="mfrAddr" id="mfrAddr" type="text" class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">办公电话</div>
						<div class="field">
							<input name="mfrTel" id="mfrTel" type="text" class="ui-textbox"  validate="{mobileAndFixedPhone:true}"
								   value="">
						</div>
					</div>
                    <div class="fieldBox col_50">
                        <div class="label">区域</div>
                        <div class="field">
                            <!-- <input name="rgnPrCd" id="rgnPrCd" type="text" class="ui-textbox" value=""> -->
                            <jsp:include page="../../system/sysRegion/region.jsp"
                                         flush="true">
                                <jsp:param name="regionShowLvl" value="2" />
                            </jsp:include>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
					<div class="fieldBox col_50">
						<div class="label">
							<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="说明：厂商金融业务放款时，用于判断放款金额是否扣除贴息费用项。"></span>放款方式
						</div>
						<div class="field">
							<select name="payTypCd" id="payTypCd" data-value=" ">
								<option value=" " checked >请选择</option>
								<c:forEach items="${payTypCdList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="caption">
						<span class="title">更多信息</span>
					</div>
					<div class="fieldBox col_33">
						<div class="label">经销品牌(卡车类)</div>
						<div class="field">
							<input type="text" id="tkBrCd" name="tkBrCd" ltype="combobox"
								   validate="{required:true}" />
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">经销品牌(乘用车类)</div>
						<div class="field">
							<input type="text" id="carBrCd" name="carBrCd" ltype="combobox"
								   validate="{required:true}" />
							<span class="requiredSymbol">*</span>
						</div>
					</div>
					<div class="fieldBox col_33">
						<div class="label">经销品牌(客车类)</div>
						<div class="field">
							<input type="text" id="busBrCd" name="busBrCd" ltype="combobox"
								   validate="{required:true}" />
							<span class="requiredSymbol">*</span>
						</div>
					</div>
				</div>
				<div class="sqPanel">
					<div class="sqPanel_head inL">
						<div class="btnsBox inLC">
							<span id="spl_rl_add_btn" class="sq-button sq-button-round" onclick="mfrRlPsnAddBtnEvent();">添加</span>
						</div>
						<span>社会关系/家庭成员</span>
					</div>
					<div class="sqPanel_body">
						<div id="ligergrid_A1" class="sq-grid"></div>
					</div>
				</div>
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="sqPanel">
						<div class="sqPanel_head inL">
							<span>变更资料</span>
							<span class="btns"><span class="sq-button sq-button-round" onclick="downloadMfrFileByUrl();">打包下载</span></span>
						</div>
						<div class="sqPanel_body">
							<div id="mfrFileInfoCfgGrid" class="sq-grid"></div>
						</div>
					</div>
				</div>
				<!-- 资料上传DIV -->
				<div id="prj_file_div" style="display:none">
					<form id="prj_file_formSet">
						<div class="fieldset1 tabel_col noBorder clearFix">
							<div class="fieldBox col_100">
								<jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true" >
									<jsp:param name="fileNum" value="1"/>
									<jsp:param name="filePath" value="prjFileInfo"/>
								</jsp:include>
							</div>
						</div>
						<input type="text" style="display: none;" id="cfgCd" name="cfgCd" value="${cfgCd}">
						<input type="text" style="display: none;" id="cfgDtlCd" name="cfgDtlCd">
						<input type="text" style="display: none;" id="orgCd" name="orgCd" value="${cfgOrgCd}">
						<input name="mfrId" id="mfrId" type="hidden" value="${mfrId}"/>
					</form>
				</div>
				<div class="btnsBox" >
					<span id="saveBtn1" onclick="inputReason()" class="sq-button sq-button-round">保存</span>
				</div>
			</form>
		</div>
		<div tabid="tabB" title="资料信息">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>
		<div tabid="tabC" title="备案账号">
			<iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
		</div>
		<div tabid="tabD" title="流程跟踪">
			<iframe frameborder="0" name="tabD" id="tabD" src=""></iframe>
		</div>
		<div tabid="tabE" title="相关项目">
			<iframe frameborder="0" name="tabE" id="tabE" src=""></iframe>
		</div>
		<div tabid="tabF" title="变更记录">
			<iframe frameborder="0" name="tabF" id="tabF" src=""></iframe>
		</div>
	</div>
</div>
<script type="text/javascript">
		var loadedTabs=[];
		var mfrRlPsnGrid;
		var isFlow = '${isFlow}';
        var mfrId = '${mfrId}';
        var modId = '${modId}';
		var isModify = '${isModify}';
		var isMdfPayTyp = '${isMdfPayTyp}';
        var currentOrgCd = '${currentOrgCd}';


        var _mfrId = '${mfrId}';
        var _isDetail = '${isDetail}';
        var _qualTypCd = '${qualTypCd }'; //经销商资质
        var _cfgSysCd = '${cfgSysCd}'; //附件系统CODE
        var _cfgOrgCd = '${cfgOrgCd}'; //附件组织架构
        var _tabNm = '${tabNm}'; //附件对应表
        var _cfgCd = '${cfgCd}'; //附件CODE
        var _modulePath = '${modulePath}';
        var _costomerPath = '${costomerPath}';
        var _rootPath = '${rootPath}';
        var _uploadSysCd = '${uploadSysCd}';
        var _isApply = '${isApply}';
        var _isCheckVerify = '${isCheckVerify}';

        var mfrFileInfoCfgGrid = null ;//资料配置明细
        var upload_result_params = [];
        var serverPrefixPath = "";

        var isMatchFileRec = '${isMatchFileRec}';

		$(function () {

            //获取服务器路径前缀
            $.ajax({
                type: 'get',
                url: '<%=path%>/system/sysulfilesrec/getServerPath.do',
                success:function(msg){
                    serverPrefixPath = msg;
                    console.log(serverPrefixPath);
                }
            });
            var _tkBrCdListJSON = ${tkBrCdListJSON};
            $("#tkBrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
                data: _tkBrCdListJSON,
                valueField: 'key',
                textField:'value'
            });
            var _carBrCdListJSON = ${carBrCdListJSON};
            $("#carBrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
                data: _carBrCdListJSON,
                valueField: 'key',
                textField:'value'
            });
            var _busBrCdListJSON = ${busBrCdListJSON};
            $("#busBrCd").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
                data: _busBrCdListJSON,
                valueField: 'key',
                textField:'value'
            });

            $("#formSet1").ligerForm({
                validate : true
            });
            $("#formSet1").ligerForm();

			initTab();
			initData();
            initMfrFileInfoCfgGrid();
			initMfrRlGrid();
            disableFiled();
		});

        /**
         * 数据加载
         */
        function initMfrFileInfoCfgGrid(){
			var id = modId;
			if(!id){
			    id = mfrId;
			}
            //资料配置明细Grid
            mfrFileInfoCfgGrid = $("#mfrFileInfoCfgGrid").ligerGrid({
                url: '<%=path%>/mfr/mfrBscInfo/initMfrFileInfoList.do?mfrId='+id+'&cfgCd='+_cfgCd +'&tabNm='+_tabNm +"&cfgSysCd="+_cfgSysCd+'&cfgOrgCd='+_cfgOrgCd,
                method: 'get',
                columns: [
                    {display: '资料名称', name: 'datNm',align: 'left', minWidth: 100, enabledSort: false},
                    {display: '上传文件名称', name: 'fileNm',align: 'left', minWidth: 100, enabledSort: false,
                        render:function(rowdata,rowindex,value){
                            if(value){
                                var h;
                                h='<a href="javascript:uploadFileByUrl(';
                                h+="'"+rowdata.filePath+"'";
                                h+=",'"+rowdata.fileNm+"'";
                                h+=')">'+rowdata.fileNm+'</a>'
                                return h;
                            }
                        }
                    },
                    {display: '上传时间', name: 'crtTm',align: 'left', minWidth: 100, enabledSort: false,render:renderDate},
                    {display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
                    {display: '操作', name: '', minWidth: 100,align: 'left',  enabledSort: false,
                        render:function(rowdata,rowindex,value){
                            var h='';
                            if(rowdata.fileId){
                                if(rowdata.audStsCd && rowdata.audStsCd != 1){
                                    h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                                }
                            }
                            return h;
                        }
                    },
                    {display: '上传', name: 'uploadNm', width: 80,align: 'left', enabledSort: false,
                        render:function(rowdata,rowindex,value){
                            var h='';
                            if(_isApply){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',\''+rowdata.fileId+'\',\''+rowindex+'\')"></span>';
                            }
                            return h;
                        }
                    },
                ],
                root: 'rows',
                hideLoadButton : true,
                width: '100%',
                height: '100%',
                isScroll: false,
                rownumbers:true,  //显示序号
                checkbox: false,
                allowUnSelectRow:true,
                alternatingRow: false,
                frozen: false,
                usePager: false,
                onAfterShowData: function ()
                {
                    $('#mfrFileInfoCfgGrid').rowspan('datNm');
                    $('#mfrFileInfoCfgGrid').rowspan('uploadNm');
                }
            });
        }

        function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd,fileId,rowIndex) {
            var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            var filePath= _modulePath; //之前无 '/'
            $.ajaxFileUpload({
                url: '<%=path%>/system/sysulfilesrec/upload.do',
                secureuri: false,
                fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
                dataType: 'json',
                data: {filePath: filePath,costomerPath:_costomerPath,rootPath:_rootPath,uploadSysCd:_uploadSysCd},
                success: function (msg) {
                    if (msg.success == 1) {
                        if(serverPrefixPath.length >1 && serverPrefixPath.indexOf("\"")>=0){
                            serverPrefixPath = serverPrefixPath.substring(1,serverPrefixPath.length-1);
                        }
                        var uploadJOSN = JSON.parse(JSON.stringify(msg.data));
                        console.log("uploadJOSN =s= " + JSON.stringify(uploadJOSN));
                        for (var i=0; i< uploadJOSN.length; i++){
                            var oldPath = "";
                            var newPath = "";
                            oldPath = uploadJOSN[i].filePath;
                            newPath = serverPrefixPath + oldPath;
                            //uploadJOSN[i].filePath = newPath;
                            mfrFileInfoCfgGrid.updateCell("filePath",oldPath,rowIndex);
                            mfrFileInfoCfgGrid.updateCell("fileNm",uploadJOSN[i].fileNm,rowIndex);
                            mfrFileInfoCfgGrid.updateCell("cfgDtlCd",cfgDtlCd,rowIndex);
                            mfrFileInfoCfgGrid.updateCell("crtTm",new Date(),rowIndex);
                            uploadJOSN[i].cfgCd = cfgCd ;
                            uploadJOSN[i].cfgDtlCd = cfgDtlCd;
                            uploadJOSN[i].orgCd = orgCd;
                            uploadJOSN[i].tabNm = _tabNm;
                            uploadJOSN[i].sysCd = _cfgSysCd;
                            upload_result_params.push(uploadJOSN[i]);
                            console.log("upload_result_params =s= " + JSON.stringify(upload_result_params));
                        }
                        wait_dialog.close();
                    } else {
                        wait_dialog.close();
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        };

        //修改资料的验证状态
        function modifyAudStsCd(event,_fileId,_audStsCd){
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {'fileId':_fileId,'audStsCd':_audStsCd},
                url: '<%=path%>/mfr/mfrBscInfo/modifyFileAudStsCd.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        //$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        event.stopPropagation();
                        var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                        liger.get(gridID).reload();
                    }else{
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }

        //删除文件
        function delFile(event,_fileId){
            top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
                if(!flag){
                    return;
                }else{
                    var wait_dialog;
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {'fileId':_fileId},
                        url: '<%=path%>/mfr/mfrBscInfo/removeFile.do',
                        beforeSend: function () {
                            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                        },
                        success: function (msg) {
                            wait_dialog.close();
                            if (msg.success == 1) {
                                $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                event.stopPropagation();

                                var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                                liger.get(gridID).reload();
                            }else{
                                $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                            }
                        }
                    });
                }
            });
        }

        function downloadMfrFileByUrl() {
            var data = mfrFileInfoCfgGrid.getData();
            //var files = [];
            var ids = [];
            for (var i = 0; i < data.length; i++) {
                var map = {};
                if(StringUtils.isNotEmpty(data[i].fileId)){
                    ids.push(data[i].fileId);
                }
            }
            var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do?';
            var form = $("<form>");
            $('body').append(form);
            form.attr('style','display:none');
            form.attr('target','');
            form.attr('method','post');
            form.attr('action',actoinURL);//下载文件的请求路径
            var input = $('<input>');
            input.attr('type','hidden');
            input.attr('name','ids');
            input.attr('value',JSON.stringify(ids));
            form.append(input);
            form.submit();
        }

        //图片展示
        function showImg(e){
            e.preventDefault();
            var href = $(e.target).attr('src');
            if(!href){
                return;
            }
            if(SQ.regs.img.test(href)){
                var imgSrc = $(e.target).attr('src'),
                    imgTit = $(e.target).attr('title');
                window.__ImgSrc = imgSrc;
                window.__ImgTit = imgTit;
                window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
            }
        }

        //删除文件
        function removeFileRec(event,_fileId){
            top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
                if(!flag){
                    return;
                }else{
                    var wait_dialog;
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {'fileId':_fileId},
                        url: '<%=path%>/mfr/mfrBscInfo/removeFile.do',
                        beforeSend: function () {
                            wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                        },
                        success: function (msg) {
                            wait_dialog.close();
                            if (msg.success == 1) {
                                $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                                refreshUlFileRecList();//刷新文件列表
                                clearUploadResultParams();//清除上传结果参数

                                var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                                liger.get(gridID).reload();
                                //var gridID = $(event.target).parents('.sq-grid').attr('ligergrid1');
                                //liger.get(gridID).reload();
                            }else{
                                $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                            }
                        }
                    });
                }
            });
        }

		/**
		 * 数据加载
		 */
		function initData(){
			var id = mfrId;
			if(!id){
				return;
			}
			var _url = '<%=path%>/mfr/mfrBscInfo/getById.do';
			if(modId){
                _url = '<%=path%>/product/mfrInfo/getMfrInfoFlowById.do';
			}
			$.ajax({
				type: 'get',
				dataType:'json',
				data:{id:id,modId:modId,currentOrgCd:currentOrgCd},
				url: _url,
				success:function(msg){
					if(msg.success == 1){
						setData(msg.data);//设置数据
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		}
		//设置页面数据
		function setData(data){
            var form = liger.get("formSet1");

            //区域数据处理
            setRgnProvCdUpdataValue(data.rgnPrCd);
            setRgnCityCdUpdataValue(data.rgnCyCd);
            setRegionSelectDataChange();

            $("#mfrNm").val(data.mfrName);
            $("#succ").val(data.succ);
            $("#mfrAddr").val(data.mfrAddr);
            $("#mfrFax").val(data.mfrFax);
            $("#mfrTel").val(data.mfrTel);
            $("#lmNm").val(data.lmNm);
            $("#lmIdNum").val(data.lmIdNum);
            //$("#lmOfficeTel").val(data.lmOfficeTel);
            $("#lmZipNo").val(data.lmZipNo);
            $("#lmAddr").val(data.lmAddr);
            $("#lmEMail").val(data.lmEMail);
            $("#lmMp1").val(data.lmMp1);
            $("#lmMp2").val(data.lmMp2);
            liger.get("payTypCd").setValue(data.payTypCd);
            liger.get("payTypCd").updateStyle();

            $("#tkBrCd").ligerGetComboBoxManager().selectValue(data.tkBrCdNms);
            $("#tkBrCd").ligerGetComboBoxManager().updateStyle();
            $("#carBrCd").ligerGetComboBoxManager().selectValue(data.carBrCdNms);
            $("#carBrCd").ligerGetComboBoxManager().updateStyle();
            $("#busBrCd").ligerGetComboBoxManager().selectValue(data.busBrCdNms);
            $("#busBrCd").ligerGetComboBoxManager().updateStyle();
		};

		//初始化Tab页
		function initTab(){
			pageInTab = $("#pageInTab").ligerTab({
				height: 'auto',
				contextmenu: false,
				minIframeHeight: 450,
				onBeforeSelectTabItem: function (tabid) {
					var _mId = mfrId;
					if(tabid!="tabA"){
						if(!_mId){
							top.$.ligerDialog.SQalert({content: "请确认厂商基本信息已存在", SQ_type: "warning"});
							return false;
						}
					}
				},
				onAfterSelectTabItem: function(tabid) {
					if (loadedTabs.indexOf(tabid)<0) {
						var _mId = mfrId;
						if(tabid!="tabA"){
							if(!_mId){
								top.$.ligerDialog.SQalert({content: "请确认厂商基本信息已存在", SQ_type: "warning"});
								return false;
							}
						}
						loadedTabs.push(tabid);
						switch (tabid){
                            case "tabB": //厂商资料
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrBscInfo/toMfrFileAddPage.do?mfrId="+ mfrId);
                                break;
                            case "tabC"://备案账号
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrbankacc/toListPageDetail.do?isDetail=1&mfrId="+mfrId );
                                break;
                            case "tabD"://流程追踪
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrBscInfo/toMfrFlowPage.do?mfrId="+mfrId);
                                break;
                            case "tabE"://相关项目
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/product/mfrInfo/toMfrPrjBscInfoDetailList.do?mfrId="+mfrId);
                                break;
                            case "tabF"://变更记录
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/mfr/mfrinfomoddtl/toListPage.do?modId="+ modId);
                                break;
						}
					};
					SetIframe_height();
				}
			});
		};

		//证件类型
		var certTypCdListJSON = [];
		<c:if test="${not empty certTypCdListJSON}"> certTypCdListJSON = ${certTypCdListJSON}; </c:if>

		//联系人类型
		var rlTypCDListJSON = [];
		<c:if test="${not empty rlTypCDListJSON}"> rlTypCDListJSON = ${rlTypCDListJSON}; </c:if>

		//联系人类型
		var mustAddRlPsnJSON = [];
		<c:if test="${not empty mustAddRlPsnTypCdJSON}">
		mustAddRlPsnJSON = ${mustAddRlPsnTypCdJSON};
		console.log("mustAddRlPsnJSON ==="+JSON.stringify(mustAddRlPsnJSON));
		</c:if>

		//初始化主要人员信息
		function initMfrRlGrid() {
            var _mId = mfrId;
            var _url = '<%=path%>/mfr/mfrrlpsn/initList.do?';
            if(modId){
                _url = '<%=path%>/mfr/mfrrlpsn/initListFlow.do?';
            }
            mfrRlPsnGrid = $("#ligergrid_A1").ligerGrid({
                url: _url,
                method : 'get',
                parms:{mfrId:_mId,modId:modId},
                async: false,
                columns: [
                    { display: '联系人姓名(<span class="c_red">*</span>)', name: 'rlNm', width: 150, editor: {type: 'text'},
                        validate: function (value,rowData) {
                            if (StringUtils.isEmpty(value) && CollectionUtils.isNotEmpty(mustAddRlPsnJSON) && mustAddRlPsnJSON.indexOf(rowData.rlTypCd) >= 0) return "此项为必填项！";
                        }
                    },
                    {
                        display: '联系人类型(<span class="c_red">*</span>)', name: 'rlTypCd', width: 140,
                        editor: {
                            type: 'select',
                            data: rlTypCDListJSON,
                            valueField: 'key',
                            textField: 'value'
                        },
                        valueField: 'rlTypCd',
                        textField: 'rlTypCdNm',
                        render: function (item) {
                            return item.rlTypCdNm;
                        },
                        validate: function (value,rowData) {
                            if (StringUtils.isEmpty(value) && CollectionUtils.isNotEmpty(mustAddRlPsnJSON) && mustAddRlPsnJSON.indexOf(rowData.rlTypCd) >= 0) return "此项为必填项！";
                        }
                    },
                    {
                        display: '证件类型(<span class="c_red">*</span>)', name: 'certTypCd', width: 140,
                        editor: {
                            type: 'select',
                            data: certTypCdListJSON,
                            valueField: 'key',
                            textField: 'value'
                        },
                        valueField: 'certTypCd',
                        textField: 'certTypCdNm',
                        render: function (item) {
                            return item.certTypCdNm;
                        },
                        validate: function (value,rowData) {
                            if (StringUtils.isEmpty(value) && CollectionUtils.isNotEmpty(mustAddRlPsnJSON) && mustAddRlPsnJSON.indexOf(rowData.rlTypCd) >= 0) return "此项为必填项！";
                        }
                    },
                    { display: '证件号(<span class="c_red">*</span>)', name: 'certNo', width: 150, editor: {type: 'text'},
                        validate: function (value,rowData) {
                            if (StringUtils.isEmpty(value) && CollectionUtils.isNotEmpty(mustAddRlPsnJSON) && mustAddRlPsnJSON.indexOf(rowData.rlTypCd) >= 0) return "此项为必填项！";
                        }
                    },
                    { display: '联系电话(<span class="c_red">*</span>)', name: 'tel', width: 150, editor: {type: 'text'},
                        validate: function (value,rowData) {
                            if (StringUtils.isEmpty(value) && CollectionUtils.isNotEmpty(mustAddRlPsnJSON) && mustAddRlPsnJSON.indexOf(rowData.rlTypCd) >= 0) return "此项为必填项！";
                        }
                    },
                    { display: '备注', name: 'rlRem', minWidth: 150, editor: {type: 'text'}},
                    { display: '操作', minWidth: 80 , align:'left',
                        render: function (rowdata, rowindex, value){
                            var d = "";
                            if(rowdata.isDefault != 1){
                                if(rowdata.id){
                                    d='<a class="sq-button-hasicon" href="javascript:deletePage(';
                                    d+="'"+rowdata.__id+"'";
                                    d+=",'"+rowdata.id+"'";
                                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
                                }else{
                                    d='<a class="sq-button-hasicon" href="javascript:deletePage(';
                                    d+="'"+rowdata.__id+"'";
                                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
                                }
                            }
                            return d;
                        }
                    }],
                onBeforeEdit: function (e) {
                    var strIsDefault = e.record.isDefault;
                    var colName = e.column.columnname;
                    if (StringUtils.isNotEmpty(strIsDefault) && strIsDefault == 1) {
                        if (colName == 'rlTypCd' || colName == 'certTypCd') {
                            e.column.editor.readonly = true;
                        } else {
                            e.column.editor.readonly = false;
                        }
                    } else {
                        e.column.editor.readonly = false;
                    }
                },
                usePager: false,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: 300,
                heightDiff: -2,
                enabledEdit: true,
                isScroll: false,
                checkbox: false,
                rownumbers: true,
                allowUnSelectRow: true,
                alternatingRow: false,
                enabledSort:false,
                onAfterShowData: function() {
                    SetIframe_height ();
                }
            });
        };

		//数据库删除联系人信息
		function deleteDB(rowdata_id, _id) {
			//删除数据库
			var _ids = [];
			_ids.push(_id);
			$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
				if (flag == false) return;
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: {ids: JSON.stringify(_ids)},
					url: '<%=path%>/mfr/mfrrlpsn/removeByIds.do',
					beforeSend: function () {
						wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
					},
					success: function (msg) {
						wait_dialog.close();
						if (msg.success == 1) {
							$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
							mfrRlPsnGrid.reload();
						} else {
							$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
						}
					}
				});
			});
		}

		//本地删除
		function deletePage(rowdata_id) {
			$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
				if (flag == false) return;
				//删除页面
				mfrRlPsnGrid.deleteRow(rowdata_id);
			})
		}

		//联系人新增
		function mfrRlPsnAddBtnEvent() {
			mfrRlPsnGrid.addRow({
				rlNm: '',
				mfrId: mfrId,
				rlTypCd: '',
				certTypCd: '',
				certNo: '',
				tel: '',
				rlRem: ''
			});
		};

        function inputReason(){
            var form = new liger.get("formSet1");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var isValid = SQ.validGrid('ligergrid_A1');
            if (isValid == false) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false;
            }
            var data = form.getData();
            var id = mfrId;
            data["id"]= id;
            data["modId"]= modId;
            data["isBsc"]= isModify;
            data["currentOrgCd"] = currentOrgCd;
            data["rgnPrCd"] = getRgnProvCd();//获取省代码
            data["rgnCyCd"] = getRgnCityCd();//获取市代码
            data["payTypCdNm"] = $('#payTypCd option:checked').text();
            var mfrRlPsnList = mfrRlPsnGrid.getData();
            data["mfrRlPsnList"] = JSON.stringify(mfrRlPsnList);
            var fileParams = upload_result_params;//getUploadResultParams(); //获取附件上传的信息
            console.log("fileParams ==" + JSON.stringify(fileParams));
            data["fileParams"] = JSON.stringify(fileParams);

            checkChangelowMfrInfo(data);

        }

        function checkChangelowMfrInfo(data) {
            $.ligerDialog.SQalert({content: "判断是否变更" , SQ_type: "warning" });
            var url = '<%=path%>/product/mfrInfo/checkChangeMfrInfo.do';
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: url,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        if (msg.info == 1) {
                            startMfrAdmissionFlow();
                        } else {
                            saveMfrInfo('');
                        }
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }

        //发起审核流程
        function startMfrAdmissionFlow() {
            var modelTyp = '044';//流程业务分类-
            if (StringUtils.isEmpty(modelTyp)) {
                return;
            }
            var flowDialog = $.ligerDialog.SQopen({
                url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp=' + modelTyp,
                width: 700,
                height: 400,
                title: '请选择要发起的流程',
                buttons: [{
                    text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        if (Dialog.onOk) {
                            $.ligerDialog.SQconfirm('是否确定发起变更流程?', function (flag) {
                                if (flag == false) {
                                    return;
                                } else {
                                    Dialog.onOk();
                                }
                            })
                        }
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
                ],
                onClose: function () {
                    var json = flowDialog._DATA;
                    if (!json) {
                        return;
                    }
                    saveMfrInfo(json);
                }
            });
        }

        function saveMfrInfo(json) {
            var form = new liger.get("formSet1");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var isValid = SQ.validGrid('ligergrid_A1');
            if (isValid == false) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false;
            }
            var data = form.getData();
            data["isFlow"] = isFlow ;
            var id = mfrId;
            data["id"]= id;
            data["modId"]= modId;
            data["currentOrgCd"] = currentOrgCd;
            data["rgnPrCd"] = getRgnProvCd();//获取省代码
            data["rgnCyCd"] = getRgnCityCd();//获取市代码
            data["payTypCdNm"] = $('#payTypCd option:checked').text();
            if (StringUtils.isNotEmpty(json)) {
                data["procDefKey"] = json.procDefKey;
                data["procDefId"] = json.procDefId;
                data["procNo"] = json.procNo;
            }
            var mfrRlPsnList = mfrRlPsnGrid.getData();
            data["mfrRlPsnList"] = JSON.stringify(mfrRlPsnList);
            var fileParams = upload_result_params;//getUploadResultParams(); //获取附件上传的信息
            console.log("fileParams ==" + JSON.stringify(fileParams));
            data["fileParams"] = JSON.stringify(fileParams);

            var url='<%=path%>/product/mfrInfo/modifyMfrInfoStartFlow.do';
            if(modId){
                url='<%=path%>/product/mfrInfo/modifyMfrAgain.do';
			}
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:data,
                url: url,
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        if(msg.data){
                            $("#mId").val(msg.data);
                        }
                        //callback回调
                        var TAB=top.mainApp.parentTab;
                        var currentTabid=TAB.getSelectedTabItemID();
                        var currentTabiframe=top.$("#"+currentTabid).get(0);
                        var callback=currentTabiframe.W2W.callback;
                        callback();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            })
        }
        //格式化时间
        function renderDate(rowdata, index, value) {
            var dateStr = "";
            if (null != value) {
                var date = new Date(value);
                dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
            }
            return dateStr;
        }
        function uploadFileByUrl(_url,_name){
            if(serverPrefixPath.length >1 && serverPrefixPath.indexOf("\"")>=0){
                serverPrefixPath = serverPrefixPath.substring(1,serverPrefixPath.length-1);
            }
            if(SQ.regs.img.test(_name)){
                //SQ.imgPreview(_url);
                //SQ.imgPreview(_url, true);
                window.__ImgSrc = serverPrefixPath + _url;
                window.__ImgTit = _name;
                window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
            }else{
                window.open(serverPrefixPath + _url);
            }
        }
        function disableFiled() {

            if (liger.get("payTypCd")) {
                liger.get("payTypCd").setDisabled(true);
            }
            if (liger.get("rlTypCd")) {
                liger.get("rlTypCd").setReadonly(true);
            }
            if (liger.get("certTypCd")) {
                liger.get("certTypCd").setReadonly(true);
            }
        }
	</script>
</body>
</html>